package c.d.a.a.e;

import c.d.a.a.f.b.d;
import c.d.a.a.j.c;
import com.github.mikephil.charting.data.Entry;
import java.util.ArrayList;
import java.util.List;

/* compiled from: ChartHighlighter */
public class a<T extends c.d.a.a.f.a.a> implements c {
    public T a;
    public List<b> b = new ArrayList();

    public a(T t) {
        this.a = t;
    }

    public b a(float f, float f2) {
        c b = this.a.a(c.d.a.a.b.i.a.LEFT).b(f, f2);
        float f3 = (float) b.b;
        c.d.c(b);
        return e(f3, f, f2);
    }

    public List<b> b(d dVar, int i, float f, c.d.a.a.c.e.a aVar) {
        ArrayList arrayList = new ArrayList();
        List K = dVar.K(f);
        if (K.size() == 0) {
            Entry q = dVar.q(f, Float.NaN, aVar);
            if (q != null) {
                K = dVar.K(q.b());
            }
        }
        if (K.size() == 0) {
            return arrayList;
        }
        for (Entry entry : K) {
            c a = this.a.a(dVar.e0()).a(entry.b(), entry.a());
            arrayList.add(new b(entry.b(), entry.a(), (float) a.b, (float) a.c, i, dVar.e0()));
        }
        return arrayList;
    }

    public c.d.a.a.c.a c() {
        return this.a.getData();
    }

    public float d(float f, float f2, float f3, float f4) {
        return (float) Math.hypot((double) (f - f3), (double) (f2 - f4));
    }

    public b e(float f, float f2, float f3) {
        List list;
        this.b.clear();
        c.d.a.a.c.a c = c();
        if (c == null) {
            list = this.b;
        } else {
            int d = c.d();
            for (int i = 0; i < d; i++) {
                d c2 = c.c(i);
                if (c2.n0()) {
                    this.b.addAll(b(c2, i, f, c.d.a.a.c.e.a.CLOSEST));
                }
            }
            list = this.b;
        }
        b bVar = null;
        if (list.isEmpty()) {
            return null;
        }
        c.d.a.a.b.i.a aVar = c.d.a.a.b.i.a.LEFT;
        float f4 = f(list, f3, aVar);
        c.d.a.a.b.i.a aVar2 = c.d.a.a.b.i.a.RIGHT;
        if (f4 >= f(list, f3, aVar2)) {
            aVar = aVar2;
        }
        f4 = this.a.getMaxHighlightDistance();
        for (int i2 = 0; i2 < list.size(); i2++) {
            b bVar2 = (b) list.get(i2);
            if (bVar2.h == aVar) {
                float d2 = d(f2, f3, bVar2.c, bVar2.d);
                if (d2 < f4) {
                    bVar = bVar2;
                    f4 = d2;
                }
            }
        }
        return bVar;
    }

    public float f(List<b> list, float f, c.d.a.a.b.i.a aVar) {
        float f2 = Float.MAX_VALUE;
        for (int i = 0; i < list.size(); i++) {
            b bVar = (b) list.get(i);
            if (bVar.h == aVar) {
                float abs = Math.abs(bVar.d - f);
                if (abs < f2) {
                    f2 = abs;
                }
            }
        }
        return f2;
    }
}
